<link rel="stylesheet" href="/static/math.css">
<link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css">
<link rel="stylesheet" href="/static/monokai.css">
<script src="/static/math.js">
</script>
<script src="/static/highlight.js"></script> 
<script src="/static/parser.js"></script>
<script>
  window.parser = window.markdownit({
      {# The lower is needed to make JS understand Python bools #}
      {% for name, value in config.EDITOR_CONF.settings.items() %}
        {{ name }}: {{ value | lower }},
      {% endfor %}
      highlight: function (str, lang) {
        if (lang && hljs.getLanguage(lang)) {
          try {
            return '<pre class="hljs"><code>' +
                    hljs.highlight(lang, str, true).value +
                    '</code></pre>';
          } catch (__) {}
        }
      }
  })
  .use(texmath.use(katex), {
    engine: katex,
    delimiters:'dollars',
    katexOptions: { macros: {"\\RR": "\\mathbb{R}"} }
  })
  {% for plugin_name, plugin_params in config.EDITOR_CONF.plugins.items() %}
    .use(window.{{plugin_name}}{% if plugin_params | length %}, {{plugin_params|tojson}}{% endif %})
  {% endfor %}
  window.parser.customRender = function(content) {
    let tag_regex = new RegExp("(^|\\n| )#([-_a-zA-ZÀ-ÖØ-öø-ÿ0-9]+)#", "g");
    let note_link_regex = /\[\[(.+)\|([0-9]+)\]\]/g;
    content = content.replace(tag_regex, "$1[#$2](/tags/$2)");
    content = content.replace(note_link_regex, "[[[$1]]](/dataobj/$2)");
    return window.parser.render(content);
  }
</script>
